#include "VMChangeEvent.h"

VMChangeEvent::VMChangeEvent(DIVA_VM* vm,float frame){
	_vm = vm;
	_pastpos = _vm->getPosition();
	_postpos = _pastpos;
	_frames = frame;
	_currentFrames = 0;
	assert(vm != NULL);
}

void VMChangeEvent::setPastpos(){
	_pastpos = _vm->getPosition();
}

void VMChangeEvent::setPostpos(){
	_postpos = _vm->getPosition();
}
Ogre::Vector3 VMChangeEvent::getPrepos(){
	return _pastpos;
}
Ogre::Vector3 VMChangeEvent::getPostpos(){
	return _postpos;
}

void VMChangeEvent::render(float timer){
	if (_currentFrames<=_frames)
	{
		Ogre::Vector3 oneframepos = (_postpos - _pastpos) / _frames;
		Ogre::Vector3 _currentpos =  _pastpos + oneframepos*_currentFrames++;
		_vm->setPosition(_currentpos);
		_currentFrames++;
	}
}

void VMChangeEvent::recover(){
	_currentpos = _pastpos;
	_currentFrames = 0;
	_vm->setPosition(_currentpos);
}

void VMChangeEvent::restart(){
	_currentpos = _pastpos;
	_currentFrames = 0;
}